//
//  RocketTabBar.m
//  RocketProject
//
//  Created by chen jiedan on 13-5-7.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RocketTabBar.h"
#import "RCSearchingMainPageVC.h"
#import "RCServiceMainVC.h"

#import "BWXSegmentBar.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "MLNavigationController.h"
//#import "RCMemberVC.h"
#import "RCMemberCardVC.h"

#import "RCMoreVC.h"
//#import "RCWaitingMoreVC.h"

#import "RCDiscountMainVC.h"
#import "RCLoginPageVC.h"
#import "RCLoginController.h"

#import "RCUserVC.h"
#import "RCSearchMoreTagsVC.h"
#import "GloableEngineService.h"

#import "RCCheckInModuleVC.h"
#import "MLNavigationController.h"

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]


@interface RocketTabBar ()<UIGestureRecognizerDelegate>

@end

@implementation RocketTabBar



-(void)initRocketTableView{
    NSMutableArray* vcArray = [NSMutableArray array];
    
    
    //        navVC.delegate = router;
    //        [(BWXTopTabBarViewController *)_viewVC setIsNavTitleView:YES];
    
#ifdef ServerVersion
    RCServiceMainVC *_viewVC = [[RCServiceMainVC alloc] init];
#else
    RCSearchingMainPageVC *_viewVC = [[RCSearchingMainPageVC alloc] init];
    
#endif
    

    _viewVC.view.backgroundColor = [UIColor whiteColor];
    MLNavigationController *navVC = [[MLNavigationController alloc] initWithRootViewController:_viewVC];
    //        if (isIOS7) {
    //            navVC.interactivePopGestureRecognizer.delegate = self;
    //
    //            navVC.interactivePopGestureRecognizer.enabled = YES;
    //        }
    
    
    [vcArray addObject:navVC];
    [navVC release];
    [_viewVC release];
    
    RCMemberCardVC *memberVC = [[RCMemberCardVC alloc] init];
    MLNavigationController *memberNav = [[MLNavigationController alloc] initWithRootViewController:memberVC];
    //        if (isIOS7) {
    //            memberNav.interactivePopGestureRecognizer.delegate = self;
    //            memberNav.interactivePopGestureRecognizer.enabled = YES;
    //        }
    
    [vcArray addObject:memberNav];
    [memberVC release];
    [memberNav release];
    
    
    RCCheckInModuleVC *checkIn = [[RCCheckInModuleVC alloc] init];
    MLNavigationController *checkNav = [[MLNavigationController alloc] initWithRootViewController:checkIn];
    //        if (isIOS7) {
    //            checkNav.interactivePopGestureRecognizer.delegate = self;
    //            checkNav.interactivePopGestureRecognizer.enabled = YES;
    //        }
    
    [vcArray addObject:checkNav];
    [checkNav release];
    [checkIn release];
    
    
    RCLoginPageVC *loginVC = [[[RCLoginPageVC alloc] init] autorelease];
    //        UINavigationController *login1 = [[[UINavigationController alloc] initWithRootViewController:loginVC] autorelease];
    
    RCUserVC *userVC = [[[RCUserVC alloc] init] autorelease];
    //        UINavigationController *login2 = [[[UINavigationController alloc] initWithRootViewController:userVC] autorelease];
    
    NSArray *vcs = [NSArray arrayWithObjects:loginVC,userVC, nil];
    //第四个tab loginVC 和userVC 做为子VC，由RCLoginController决定显示那个
    RCLoginController *loginController = [[[RCLoginController alloc] initWithViewControllers:vcs] autorelease];
    loginVC.delegate = loginController;
    userVC.delegate = loginController;
    
    MLNavigationController *personalNav = [[[MLNavigationController alloc] initWithRootViewController:loginController] autorelease];
    //        if (isIOS7) {
    //            personalNav.interactivePopGestureRecognizer.delegate = self;
    //            personalNav.interactivePopGestureRecognizer.enabled = YES;
    //        }
    
    [vcArray addObject:personalNav];
    
    
    
    
    RCMoreVC *moreVC = [[RCMoreVC alloc] init];
    MLNavigationController *moreNavVC = [[MLNavigationController alloc] initWithRootViewController:moreVC];
    //        if (isIOS7) {
    //            moreNavVC.interactivePopGestureRecognizer.delegate = self;
    //            moreNavVC.interactivePopGestureRecognizer.enabled = YES;
    //        }
    
    
    [vcArray addObject:moreNavVC];
    [moreVC release];
    [moreNavVC release];
    
    BWXSegmentBar* segmentBar = [[BWXSegmentBar alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];
    NSArray* images = ObjectsArray(@"image_tabbar_search_normal.png", @"image_tabbar_member_normal.png",@"image_tabbar_discount_normal.png",@"image_tabbar_personal_normal.png",@"image_tabbar_more_normal.png");
    NSArray* selectedImages = ObjectsArray(@"image_tabbar_search_pressed.png", @"image_tabbar_member_pressed.png",@"image_tabbar_discount_pressed.png",@"image_tabbar_personal_pressed.png",@"image_tabbar_more_pressed.png");
    [segmentBar setImages:images selectedImages:selectedImages offTop:5];
    
    [segmentBar setText:ObjectsArray(@"查找", @"会员", @"签到",@"我的", @"更多")
              textColor:RGBCOLOR(175,175,175)
            selectColor:[UIColor whiteColor]
                   font:[UIFont fontWithName:kFontNameHeiti size:12]
              offBottom:6];
    
    [segmentBar setBgColor:RGBCOLOR(51,51,51)
               selectColor:RGBCOLOR(41,41,41)];
    
    self.viewControllers = vcArray;
    self.tabBarView = segmentBar;
    BWXSafeRelease(segmentBar);
}

- (void) segmentBar:(BWXSegmentBar*)bar didSelectIndex:(NSInteger)index preIndex:(NSInteger)preIndex{
    [super segmentBar:bar didSelectIndex:index preIndex:preIndex];
    
    
    //    if (index == 0) {
    //        UINavigationController *firstNav = [self selectedViewController];
    //        if ([firstNav.viewControllers count] == 1) {
    //            self.tabBarHide = NO;
    //        }else{
    //            self.tabBarHide = YES;
    //        }
    //    }else if (index == 1){
    //        self.tabBarHide = NO;
    //    }
    
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
